package cn.bluemobi.platform.controller.controlAudit;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.controller.PlatformBaseController;
import cn.bluemobi.platform.core.dto.DatatablePage;
import cn.bluemobi.platform.entity.controlAudit.ControlAudit;
import cn.bluemobi.platform.service.ControlAuditService;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/admin/controlAudit")
public class ControlAuditController extends PlatformBaseController {

	@Autowired
	private ControlAuditService controlAuditService;

	@RequestMapping("/toControlAuditPage")
	public String toControlAuditPage(Model model) {
		return "controlAudit/controlAuditList";
	}

	@RequestMapping("/findControlAudits")
	@ResponseBody
	public DatatablePage findControlAudits(PageCondition cond) {
		return new DatatablePage(cond,
				controlAuditService.findControlAudits(cond));
	}

	@RequestMapping("/toControlAuditDetailPage")
	public String toControlAuditDetailPage(
			@RequestParam(value = "controlAuditId", required = false) String controlAuditId,
			ModelMap model) {
		if (!StringUtils.isEmpty(controlAuditId)) {
			ControlAudit controlAudit = controlAuditService
					.findControlAuditDetail(controlAuditId);
			model.put("controlAudit", controlAudit);
		}
		return "controlAudit/controlAuditDetail";
	}

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public MapDto saveOrUpdate(ControlAudit controlAudit) {
		return controlAuditService.saveOrUpdate(controlAudit, getUser());
	}

	@RequestMapping("/deleteControlAudit")
	@ResponseBody
	public MapDto deleteControlAudit(
			@RequestParam("controlAuditId") String controlAuditId) {
		return controlAuditService
				.deleteControlAudit(controlAuditId, getUser());
	}

}
